
package com.crv.ci.action;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crv.common.domain.view.BizData4Page;
import com.crv.ci.model.TemplateDynaParams;
import com.crv.ci.service.ITemplateDynaParamsService;
import com.crv.common.utils.IdGenerator;
import com.crv.common.utils.JsonResult;
import com.crv.common.utils.PageParam;
import com.crv.common.utils.Constants;

@Controller
public class TemplateDynaParamsAction extends AbstractAdminController<ITemplateDynaParamsService>{

    @Autowired
    private ITemplateDynaParamsService templateDynaParamsService;
    
    @RequestMapping(value="/templatedynaparams/list")
    public String list(TemplateDynaParams templateDynaParams,ModelMap model,PageParam pageParam,HttpServletRequest request,HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(templateDynaParams); 	
    	BizData4Page<TemplateDynaParams> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("templateDynaParams", templateDynaParams);
    	return "/module/templatedynaparams/list";
    }    
    
    @RequestMapping(value="/templatedynaparams/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("templateDynaParams", new TemplateDynaParams());
        return "module/templatedynaparams/edit";
    }    
    
    @RequestMapping(value="/templatedynaparams/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	TemplateDynaParams templateDynaParams = templateDynaParamsService.fetch(id);
    	model.addAttribute("templateDynaParams", templateDynaParams);
        return "module/templatedynaparams/edit";
    }    
    
    @RequestMapping(value="/templatedynaparams/save")
    @ResponseBody
    public String save(HttpServletRequest request,TemplateDynaParams templateDynaParams){
		boolean isAddNew = StringUtils.isBlank(templateDynaParams.getId())?true:false;
		if(isAddNew)
		{
			templateDynaParams.setId(IdGenerator.createNewId());
			templateDynaParamsService.add(templateDynaParams);
		}
		else
		{
			templateDynaParamsService.update(templateDynaParams);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/templatedynaparams/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	templateDynaParamsService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(TemplateDynaParams templateDynaParams)
    {
    	Map<String, Object> conditions = new HashMap();
    	
		conditions.put("templateId", templateDynaParams.getTemplateId());		
		conditions.put("paramId", templateDynaParams.getParamId());		
		conditions.put("paramName", templateDynaParams.getParamName());		
		conditions.put("note", templateDynaParams.getNote());		
		conditions.put("createDate", templateDynaParams.getCreateDate());		
    	return conditions;
    }

    @Override
    protected ITemplateDynaParamsService getMainService() {
        return templateDynaParamsService;
    }

    @Override
    protected String getMainObjName() {
        return "templatedynaparams";
    }

    @Override
    protected String getViewTitle() {
        return "templatedynaparams";
    }
}
